package com.skd.mall.product.controller.web;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skd.mall.product.entity.CategoryEntity;
import com.skd.mall.product.service.CategoryService;
import com.skd.mall.product.vo.Catalog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.Model;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping({"/","/index"})
    public String index(Model model){
        List<CategoryEntity> list = categoryService.list(new QueryWrapper<CategoryEntity>().eq("cat_level", 1));
        model.addAttribute("categorys", list);
        return "index";
    }

    @ResponseBody
    @RequestMapping("/index/catalog.json")
    public Map<String,List<Catalog2VO>> getCatalog2JSON(){
        Map<String,List<Catalog2VO>> map = categoryService.getCatalog2JSON();
        return map;
    }
}
